
// 自定义日志控制对象
const dconsole = {
    _enabled: true, // 控制开关，改为false或注释此行就能禁用所有dconsole日志

    log(...args) {
        if (this._enabled) {
            console.log(...args);
        }
    }
};

// 修改后的watch函数，使用dconsole替代console.log
function watch(func, name) {
    return new Proxy(func, {
        get(target, p, receiver) {
            // 需要跳过打印的属性名单
            const skipProps = ['Math', 'isNaN', 'encodeURI', 'Uint8Array', 'Array', 'String', "parseFloat", "parseInt", "Date", "RegExp", "Object"];
            // Check if property should be skipped
            if (skipProps.includes(p)) {
                return Reflect.get(target, p, receiver); // Skip logging for specified properties
            }

            // 获取属性值
            const val = Reflect.get(target, p, receiver);

            // 处理 Symbol 类型的属性名
            const propName = typeof p === 'symbol' ? p.toString() : p;
            console.log('取值:', `${name}.${propName}`, '=>', val); // 使用 console.log 而不是 dconsole.log
            return val;
        },
        set(target, p, value, receiver) {
            // 获取新值并不进行打印
            const oldValue = Reflect.get(target, p, receiver);

            // 处理 Symbol 类型的属性名
            const propName = typeof p === 'symbol' ? p.toString() : p;
            console.log('设置值:', `${name}.${propName}`, oldValue, '=>', value); // 这行代码会打印每次设置值时的旧值和新值

            return Reflect.set(target, p, value, receiver);
        }
    });
}

Window = function () {
    return global;
}
window = new Window()
delete global
delete __filename
delete __dirname
delete Buffer


// window.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

document = {}
navigator = {}
location = {
}
localStorage = {
    getItem: function (val) {
        dconsole.log("getItem==>", val)
    },
    setItem: function (key, val) {
        dconsole.log("setItem==>", key, val)
    },
}
sessionStorage = {
    getItem: function (val) {
        dconsole.log("getItem==>", val)
    },
    setItem: function (key, val) {
        dconsole.log("setItem==>", key, val)
    },
}
screen = {
}
history = {}
window = watch(window, "window")
document = watch(document, "document")
navigator = watch(navigator, "navigator")
location = watch(location, "location")
localStorage = watch(localStorage, "localStorage")
sessionStorage = watch(sessionStorage, "sessionStorage")
screen = watch(screen, "screen")
history = watch(history, "history")



